#pragma once
#include<string>

#include "noncopyable.h"

enum LogLevel
{
    INFO,
    ERROR,
    FATAL,
    DEBUG,//调试信息
};

#define LOG_INFO(LogMsgFormat, ...)\
    do{\
        char buf[1024] = {0};\
        Logger &logger = Logger::instance();\
        int n = snprintf(buf,1024,"%s:%d:%s(): ",__FILE__,__LINE__,__FUNCTION__);\
        snprintf(buf + n, 1024 - n, LogMsgFormat, ##__VA_ARGS__);\
        logger.setLogLevel(INFO);\
        logger.log(buf);\
    }while(0)

#define LOG_ERROR(LogMsgFormat, ...)\
    do{\
        char buf[1024] = {0};\
        Logger &logger = Logger::instance();\
        snprintf(buf, 1024, LogMsgFormat, ##__VA_ARGS__);\
        logger.setLogLevel(ERROR);\
        logger.log(buf);\
    }while(0)

#define LOG_FATAL(LogMsgFormat, ...)\
    do{\
        char buf[1024] = {0};\
        Logger &logger = Logger::instance();\
        snprintf(buf, 1024, LogMsgFormat, ##__VA_ARGS__);\
        logger.setLogLevel(FATAL);\
        logger.log(buf);\
        exit(-1);\
    }while(0)

#ifdef MUDUO_DEBUG
#define LOG_DEBUG(LogMsgFormat, ...)\
    do{\
        char buf[1024] = {0};\
        Logger &logger = Logger::instance();\
        snprintf(buf, 1024, LogMsgFormat, ##__VA_ARGS__);\
        logger.setLogLevel(DEBUG);\
        logger.log(buf);\
    }while(0)
#else
#define LOG_DEBUG(LogMsgFormat, ...)
#endif
class Logger :noncopyable
{
public:
    // 获取日志唯一的实例对象
    static Logger& instance();
    // 设置日志级别
    void setLogLevel(int level);
    // 写日志
    void log(std::string msg);

private:
    /* data */
    int loglevel_;
    Logger()
    {

    }
};


